#pragma once

#include "PC2Node.h"


#include "Message.h"

namespace PC2
{

class ParticipantExecutor;
class TransactionInfoSet;

class PC2Participant
	: public PC2Node
{

public:
	PC2Participant(NodeInfo const& aID, char const* apDBPath, NodeInfo const& aCoordinatorID, std::vector<NodeInfo> const& aParticipantIDSet);
	virtual ~PC2Participant();

public:
	void SetExecutor(ParticipantExecutor* apExecutor);

public:
	void Run();
	
protected:
	void LoopForCurrentTransaction();

protected:
	bool WaitForRequestFromCoordinator(TransactionInfoSet* apInfoSet);

protected:
	void HandlePrepareRequest(TransactionInfoSet* apInfoSet, Trans* apReceivedTrans, std::string* apData);
	void HandleActionRequest(TransactionInfoSet* apInfoSet, Trans* apReceivedTrans);
	void SendDecisionRequest(uint32_t aTransID, std::set<uint32_t>* apParts);

protected:
	NodeInfo m_CoordinatorInfo;
	ParticipantExecutor* m_pExecutor;

};




}